package com.qianlou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.qianlou.common.enums.YesOrNo;
import com.qianlou.common.result.PagedResult;
import com.qianlou.mapper.JobCustomMapper;
import com.qianlou.mapper.JobMapper;
import com.qianlou.pojo.Job;
import com.qianlou.pojo.bo.JobBO;
import com.qianlou.pojo.vo.JobVO;
import com.qianlou.service.JobService;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 职位信息表 服务实现类
 * </p>
 *
 * @author James
 * @since 2025-04-26
 */
@Service
public class JobServiceImpl extends ServiceImpl<JobMapper, Job> implements JobService {

    @Resource
    private JobMapper jobMapper;

    @Resource
    private JobCustomMapper jobCustomMapper;

    @Override
    public void createOrUpdate(JobBO jobBO) {
        Job job = new Job();
        BeanUtils.copyProperties(jobBO, job);
        job.setUpdatedTime(LocalDateTime.now());
        if (StringUtils.isBlank(job.getId())) {
            job.setCreateTime(LocalDateTime.now());
            jobMapper.insert(job);
        } else {
            jobMapper.updateById(job);
        }
    }

    @Override
    public PagedResult selectJobList(Integer page, Integer size) {
        PageHelper.startPage(page, size);
        Map<String, Object> paramsMap = new HashMap<>();
        List<JobVO> jobList = jobCustomMapper.selectJobList(paramsMap);
        return PagedResult.of(jobList, page);
    }

    @Override
    public Long getJobCountInInterviewer(String interviewerId) {
        QueryWrapper<Job> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("interviewer_id", interviewerId);
        return jobCustomMapper.selectCount(queryWrapper);
    }

    @Override
    public List<HashMap<String, String>> getNameList() {
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("status", YesOrNo.YES.getType());
        return jobCustomMapper.getNameList(paramsMap);
    }
}
